package com.mall.bargain.controller;

import com.mall.bargain.service.IReceiveAddressService;
import com.mall.common.annotation.IngoreResponseAdvice;
import com.mall.common.response.CommonResponse;
import com.mall.constant.enums.CommonStatus;
import com.mall.constant.strings.SuccessMsg;
import com.mall.entity.TbCity;
import com.mall.entity.bargain.BgReceiveAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * created with IntelliJ IDEA
 *
 * @author: S
 * @date: 2021/07/19/14:35
 * Other:  发货地址控制层
 */
@RestController
@RequestMapping("/receiveAddress")
public class ReceiveAddressController {

    @Autowired
    private IReceiveAddressService receiveAddressService;

    /**
     * 添加收货地址
     *
     * @param receiveAddress 收货信息
     * @return {@link CommonResponse}
     */
    @PostMapping("/addAddress")
    public CommonResponse addAddress(@RequestBody BgReceiveAddress receiveAddress){
        return receiveAddressService.addAddress(receiveAddress);
    }

    /**
     * 三级城市联动
     * 三个下拉框的情况
     * @param id
     * @return {@link List<TbCity>}
     */
    @GetMapping("/findCity")
    public List<TbCity> addAddress(Integer id){
        return receiveAddressService.findCity(id);
    }

    /**
     * 三级城市联动
     * 一个下拉框的情况
     * @return {@link List<TbCity>}
     */
    @GetMapping("/findAllCity")
    public List<TbCity> findAllCity(){
        return receiveAddressService.findAllCity();
    }

    /**
     * 根据用户id查询该用户收货地址
     * @return {@link Integer uid}
     */
    @GetMapping("/findAddressByUid")
    @IngoreResponseAdvice
    public List<BgReceiveAddress> findAddressByUid(Integer uid){
        return receiveAddressService.findAddressByUid(uid);
    }

}
